/*
    Borealis Library
    A library of commonly used hydrological modeling building blocks

    Copyright (C) 2008  Chris Marsh

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "AsciiRaster_UnitTest.h"

CPPUNIT_TEST_SUITE_REGISTRATION( AsciiRasterTest );


void AsciiRasterTest::TestScaleBy()
{
	Borealis::AsciiRaster file;
	float scale = 5.0F;

	file.OpenFromFile("AsciiRaster_UnitTest_file1.txt" );

	file.ScaleBy(scale);
	float inputTest[3][2] = { {60.959999F*scale,60.959999F*scale},{45.847F*scale,3829.568F*scale},{-12.0F*scale,-3.14F*scale}};

	CPPUNIT_ASSERT(file.GetRasterAt(0,0) == inputTest[0][0]);
	CPPUNIT_ASSERT(file.GetRasterAt(0,1) == inputTest[0][1]);

	CPPUNIT_ASSERT(file.GetRasterAt(1,0) == inputTest[1][0]);
	CPPUNIT_ASSERT(file.GetRasterAt(1,1) == inputTest[1][1]);

	CPPUNIT_ASSERT(file.GetRasterAt(2,0) == inputTest[2][0]);
	CPPUNIT_ASSERT(file.GetRasterAt(2,1) == inputTest[2][1]);

}

void AsciiRasterTest::TestOpenFromFile()
{
	Borealis::AsciiRaster file1;
	file1.OpenFromFile(("AsciiRaster_UnitTest_file1.txt" ));

	CPPUNIT_ASSERT(file1.GetCol() == 2);
	CPPUNIT_ASSERT(file1.GetRow() == 3);

	CPPUNIT_ASSERT(file1.GetXllCorner() == 547502);
	CPPUNIT_ASSERT(file1.GetYllCorner() == 7617226);
	CPPUNIT_ASSERT(file1.GetCellSize() == 10);
	CPPUNIT_ASSERT(file1.GetNoData() == -9999.0F);

	float input1[3][2] = { {60.959999F,60.959999F},{45.847F,3829.568F},{-12.0F,-3.14F}};

	CPPUNIT_ASSERT(file1.GetRasterAt(0,0) == input1[0][0]);
	CPPUNIT_ASSERT(file1.GetRasterAt(0,1) == input1[0][1]);

	CPPUNIT_ASSERT(file1.GetRasterAt(1,0) == input1[1][0]);
	CPPUNIT_ASSERT(file1.GetRasterAt(1,1) == input1[1][1]);

	CPPUNIT_ASSERT(file1.GetRasterAt(2,0) == input1[2][0]);
	CPPUNIT_ASSERT(file1.GetRasterAt(2,1) == input1[2][1]);

	file1.SetRasterAt(0,0,3.14F);

	CPPUNIT_ASSERT(file1.GetRasterAt(0,0) == 3.14F);

	CPPUNIT_ASSERT(file1.GetCol() == 2);
	CPPUNIT_ASSERT(file1.GetRow() == 3);

	file1.SaveToXYZ(("out_xyz.txt"));


}

void AsciiRasterTest::setUp()
{

}

void AsciiRasterTest::tearDown()
{

}

void AsciiRasterTest::TestRasterAtThrow()
{
	Borealis::AsciiRaster file;
	file.GetRasterAt(0,1);
}
void AsciiRasterTest::TestSaveToFileThrow()
{
	Borealis::AsciiRaster file;
	file.SaveToFile("asdf.txt");
}
void AsciiRasterTest::TestSaveToXYZThrow()
{
	Borealis::AsciiRaster file;
	file.SaveToXYZ("asdf.txt");
}
void AsciiRasterTest::TestOpenFromFileThrow()
{
	Borealis::AsciiRaster file;
	file.OpenFromFile("bad_file_name.txt");
}

void AsciiRasterTest::TestCopyAndAssignment()
{
	Borealis::AsciiRaster file;
	Borealis::AsciiRaster file2;
	Borealis::AsciiRaster* file3;

	file.OpenFromFile("AsciiRaster_UnitTest_file1.txt");

	file.GetCol();
	file.GetRow();

	file2 = file;

	file.SetRasterAt(0,0,123.456789F);
	CPPUNIT_ASSERT(file2.GetRasterAt(0,0) == 60.959999F);

// 	file3 = new Borealis::AsciiRaster(file2);
// 	CPPUNIT_ASSERT(file3->GetRasterAt(0,0) == 123.456789F);
// 
// 	delete file3;

}







